<?php

// $Id$


require_once($WSC->get_site_inc_dir().'modules/admin_panel/site_admin_web_page_wed_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/admin_panel/classes/admin_user/admin_user_dbc.class.php');

require_once($WSC->get_site_inc_dir().'modules/tree_menu/tree_menu_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tree_menu_ml/tree_menu_ml_preparer.class.php');
require_once($WSC->get_site_inc_dir().'modules/language_detector_advanced/vl_language_dbc.class.php');


class Menu_Regenerate_WP extends Site_Admin_Web_Page_WED_UA {
	public function init() {
		parent::init();

		$v = $this->create_view();
		$this->add_view($v);
		$v2 = $this->create_view('regenerated');
		$this->add_view($v2);


		$this->wed->add_wed_event_action_pair(new Web_Event_Simple_Int('confirmed', Tangra_Parameter_Method::GET, 'confirmed'), 'confirmed_event');
		$this->wed->add_wed_event_action_pair(new Web_Event_Simple_Int('regenerated', Tangra_Parameter_Method::GET, 'regenerated'), 'regenerated_event');
	}



	protected function default_event() {
		$view = $this->get_view('default');


		return $view;
	}


	protected function confirmed_event() {
		$dbc = $this->get_dbc();

		$lang_code = $this->_config->get_current_language();
		$lang_arr = VL_Language_DBC::load_all_languages_ids($dbc);

		foreach($lang_arr as $lang) {
			Tree_Menu_ML_Preparer::generate_menu($dbc,
													'admin_',
													'navmenu-v',
													$this->_config->get_scratch_dir().'tpl/menu/',
													$this->_config->get_tpl_dir().'modules/tree_menu/tree_menu.tpl',
													$this->_config->get_scratch_dir().'tpl/menu/import/',
													$lang,
													$lang_arr);
		}

		$redir_view = $this->create_redirect_view('admin/menu/menu_regenerate.php', array('regenerated' => 1));

		return $redir_view;
	}


	protected function regenerated_event() {
		$view = $this->get_view('regenerated');


		return $view;
	}
}